package com.zhiqianbao.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhiqianbao.R;
import com.zhiqianbao.entity.Bank;

import java.util.List;

/**
 * Created by liang on 2016/1/19.
 */
public class BankListAdapter extends BaseAdapter {
    List<Bank> list;
    private LayoutInflater inflater;
    private Activity ctx;

    public BankListAdapter(Activity context, List<Bank> list) {
        this.ctx = context;
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }


    private final class ListItemView {
        //银行logo
        ImageView imageViewLogo;
        //银行名称
        TextView textViewName;
        //银行Id
        TextView bankId;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ListItemView listItemView = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.list_item_bank, null);
            listItemView = new ListItemView();
            listItemView.imageViewLogo = (ImageView) convertView.findViewById(R.id.imageView_logo);
            listItemView.textViewName = (TextView) convertView.findViewById(R.id.textView_name);
            listItemView.bankId = (TextView) convertView.findViewById(R.id.bank_id);
            convertView.setTag(listItemView);
        } else {
            listItemView = (ListItemView) convertView.getTag();
        }

        Bank bank = list.get(position);
        //TODO 未作logo显示
        listItemView.textViewName.setText(bank.getName());
        listItemView.bankId.setText(bank.getId() + "");

        return convertView;
    }
}
